<html>
	<head>
		<title>dojo/request/script</title>
		<style type="text/css">
			@import "../../resources/dojo.css";
		</style>
		<script>
			var dojoConfig = {
				async: true
			};
		</script>
		<script type="text/javascript" src="../../dojo.js"></script>
		<script type="text/javascript">
			var request, fr;
			require(["dojo/request/script", "dojo/errors/RequestTimeoutError", "dojo/errors/CancelError", "doh", "dojo/_base/window", "dojo/domReady!"], function(script, RequestTimeoutError, CancelError, doh, win){
				doh.register("dojo/request/script", [
					function load(t){
						//t.is("undefined", typeof(scriptLoad));
						var d = new doh.Deferred();
						var td = script.get("scriptDummyMethod.php", {
							query: {
								scriptVar: "scriptLoad"
							}
						}).then(d.getTestCallback(function(data){
							t.isNot("undefined", typeof scriptLoad);
							t.is("loaded", scriptLoad);
						}), function(error){
							d.errback(error);
						});
						return d;
					},
					function checkString(t){
						var d = new doh.Deferred();
						script.get("scriptDummyMethod.php", {
							query: {
								checkString: "myTasks"
							},
							checkString: "myTasks"
						}).then(d.getTestCallback(function(data){
							t.isNot("undefined", typeof myTasks);
							t.is("Do dishes.", myTasks[1]);
						}), function(error){
							d.errback(error);
						});
						return d;
					},
					function jsonp(t){
						var d = new doh.Deferred();
						script.get("scriptDummyMethod.php", {
							query: { foo: "bar" },
							jsonp: "callback"
						}).then(d.getTestCallback(function(data){
							t.is("mammal", data.animalType);
						}), function(error){
							d.errback(error);
						});
						return d;							
					},
					function jsonpTimeout(t){
						var d = new doh.Deferred();
						script.get("scriptDummyMethod.php", {
							query: { delay: 3 },
							timeout: 500,
							jsonp: "callback"
						}).then(function(data){
							d.errback(false);
						}, d.getTestCallback(function(error){
							t.t(error instanceof RequestTimeoutError);
						}));
						return d;
					},
					function jsonpCancel(t){
						var d = new doh.Deferred();
						script.get("scriptDummyMethod.php", {
							query: { delay: 3 },
							jsonp: "callback"
						}).then(function(data){
							d.errback(false);
						}, d.getTestCallback(function(error){
							t.t(error instanceof CancelError);
						})).cancel();
						return d;
					}
				]);
				doh.run();
			});
		</script>
	</head>
	<body>
		<h1>dojo/request/script test</h1>
	</body>
</html>
